package 带分数;

import java.util.Scanner;

public class Main {
    static int N = 10, n, ans;
    static boolean[] st = new boolean[N];
    static boolean[] backup = new boolean[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        dfs_a(0);
        System.out.println(ans);
    }

    private static void dfs_a(int a) {
        if (a >= n) {
            return;
        }
        if (a > 0) {
            dfs_c(a, 0);
        }
        for (int i = 1; i <= 9; i++) {
            if (!st[i]) {
                st[i] = true;
                dfs_a(a * 10 + i);
                st[i] = false;

            }
        }
    }

    private static void dfs_c(int a, int c) {
        if (c > 0 && check(a, c)) {
            ans++;
        }
        for (int i = 1; i <= 9; i++) {
            if (!st[i]) {
                st[i] = true;
                dfs_c(a, c * 10 + i);
                st[i] = false;

            }
        }
    }

    private static boolean check(int a, int c) {
        long b = n * (long) c - c * a;
        if (b == 0) {
            return false;
        }
        backup = st.clone();
        while (b > 0) {
            int t = (int) (b % 10);
            b /= 10;
            if (t == 0 || backup[t]) {
                return false;
            }
            backup[t] = true;
        }
        for (int i = 1; i <= 9; i++) {
            if (!backup[i]) {
                return false;
            }
        }
        return true;
    }
}
